﻿<cfscript>
    view = createObject("component", "#session.rootDir#.views.layout");
    view.init("Dynamic Group Management", 
        "/jquery/ui-1.8.10/jquery-ui.min.js, /#session.rootDir#/static/js/search.js, /#session.rootDir#/static/js/viewgroup.js", 
        "/jquery/ui-1.8.10/themes/cupertino/jquery-ui-1.8.10.custom.css", main,0,0,'sideBarLeft',sideBar);
    view.html();        
</cfscript>

<cffunction name="sideBar" access="public" output="true" returntype="any">
    <div id="sideBarLeft">
        <h2>Options</h2>
        <div id="sideBarLinks">
            <a href="editgroup.cfm?ADGroup=#url.ADGroup#" id="edit_group">Edit Group</a>
        </div>
    </div>
    
</cffunction>


<cffunction name="main" access="public" output="true" returntype="any">
    <cfparam default="none" name="url.ADGroup" />
    <style>
        ul.ui-autocomplete{text-align:left;}
        ##groupattrs td{vertical-align:top;}
    </style>
    <cfscript>
        import models.*;
        Group = createObject("component", "#session.rootDir#.objects.Groups").init();
        User = createObject("component", "#session.rootDir#.objects.Users").init();
        Group.setADGroup(url.ADGroup);
        GroupAttrs = Group.GroupAttrs;
        Designees = EntityLoad("Designees", {ADGroup = GroupAttrs.GroupDN});
        Guests = EntityLoad("GuestAccess", {GroupDN = GroupAttrs.GroupDN});
        AjaxController = '/#session.rootDir#/controller/AjaxHandler.cfm';
        ViewUser = "/#session.rootDir#/users/viewuser.cfm?ADUser=";
        ViewGroup = "/#session.rootDir#/groups/viewgroup.cfm?ADGroup=";
    </cfscript>
    
    <cfform name="myfrm">
        <cfinput type="hidden" name="ViewUser" value="#ViewUser#"/ >
        <cfinput type="hidden" name="ViewGroup" value="#ViewGroup#"/ >
        <cfinput type="hidden" value="#AjaxController#" name="AjaxController" />
        <cfinput type="hidden" value="#GroupAttrs.GroupDN#" name="GroupDN" />
        <cfinput type="hidden" value="#CGI.AUTH_USER#" name="IntranetUser" />
        
        <div>
            <cfinput type="text" value="Search for group" name="GroupSearch" size="30" />
            <img src="/#SESSION.RootDir#/images/progress.gif" width="16px" height="16px" id="GroupProgress" style="display:none;" align="absmiddle" />
        </div>
        
        <h2><strong>#url.ADGroup#</strong></h2>
        <table id="groupattrs" class="dataTable" width="100%">
            <tbody>
                <tr>
                    <td nowrap="nowrap">
                        <strong>Manager</strong><br /><br />
                        <cftry>
                            <cfimage action="info" source="#GroupAttrs.GroupManagerAttrs.Badge#" structname="BadgePic">
                            <cfif BadgePic.height GT 200 OR BadgePic.width GT 200>
                                <img src="#GroupAttrs.GroupManagerAttrs.Badge#" width="#(BadgePic.width * (200 / BadgePic.height))#" height="200" title="#GroupAttrs.GroupManagerAttrs.displayName#" />
                            <cfelse>
                                <img src="#GroupAttrs.GroupManagerAttrs.Badge#" width="#BadgePic.width#" height="#BadgePic.height#" title="#GroupAttrs.GroupManagerAttrs.displayName#" />
                            </cfif>
                        <cfcatch type="Any" >
                        </cfcatch>
                        </cftry>
                    </td>
                    <td nowrap="nowrap">                      
                        Login: <a href="#ViewUser##trim(GroupAttrs.GroupManagerAttrs.sAmAccountName)#">#GroupAttrs.GroupManagerAttrs.sAmAccountName#</a><br />
                        Name: #GroupAttrs.GroupManagerAttrs.displayName#<br />
                        Title: #GroupAttrs.GroupManagerAttrs.title#<br />
                        Department: #GroupAttrs.GroupManagerAttrs.department#<br />                    
                        Email: <a href="mailto:#trim(GroupAttrs.GroupManagerAttrs.userPrincipalName)#">#GroupAttrs.GroupManagerAttrs.userPrincipalName#</a>
                    </td>
                </tr>
                <tr>
                    <td nowrap="nowrap">
                        <strong>Designees</strong>
                    </td>
                    <td>
                        <ul>
                        <cfset AutomaticDesignees = User.getSupervisorLatterUp( Group.GroupAttrs.managedBy ) />
                        <cfloop from="#ArrayLen(AutomaticDesignees)#" to="1" index="i" step="-1">
                            <cfset Member = Group.SCFAD.getAccountNameByDN(AutomaticDesignees[i]) />                                                      
                            <li>
                                <a href="#ViewUser##trim(Member)#">#trim(Member)#</a>
                            </li>
                        </cfloop>
                        <!---//database added desginees--->
                        <cfloop from="1" to="#ArrayLen(Designees)#" index="i">
                            <li id="#Designees[i].getRosettaID()#">
                                <a href="#ViewUser##trim(Designees[i].getADUserAccount())#">#trim(Designees[i].getADUserAccount())#</a>
                            </li>
                        </cfloop>
                        </ul>
                    </td>                  
                </tr>
                
                    <tr>
                        <td nowrap="nowrap"><strong>Members</strong></td>
                        <td>
                            <ul>
                            <cfset GroupMembers = Group.parseUserDNString(GroupAttrs.member) />
                            <cfloop from="1" to="#ArrayLen(GroupMembers)#" index="i">
                                <cfset Member = Group.SCFAD.getAccountNameByDN(GroupMembers[i]) />
                                <li><a href="#ViewUser##trim(Member)#">#trim(Member)#</a></li>
                            </cfloop>
                            </ul>
                        </td>
                    </tr>
                    
                    <tr>
                        <td nowrap="nowrap"><strong>Guests</strong></td>
                        <td>
                            <ul>
                            <cfloop from="1" to="#ArrayLen(Guests)#" index="i">
                                <cfset Member = Group.SCFAD.getAccountNameByDN(Guests[i].getUserDN()) />
                                <li><a href="#ViewUser##trim(Member)#">#trim(Member)#</a></li>
                            </cfloop>
                            </ul>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap="nowrap"><strong>Guest Group</strong></td>
                        <td>
                            <ul>
                                <li><a href="#ViewGroup##trim(GroupAttrs.GuestGroup.sAmAccountName)#">#GroupAttrs.GuestGroup.sAmAccountName#</a></li>
                            </ul>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap="nowrap"><strong>Resource Group</strong></td>
                        <td>
                            <ul>
                                <li><a href="#ViewGroup##trim(GroupAttrs.ResourceGroup.sAmAccountName)#">#GroupAttrs.ResourceGroup.sAmAccountName#</a></li>
                            </ul>
                        </td>
                    </tr>
                <tr>
                    <td nowrap="nowrap"><strong>Type</strong></td>
                    <td>#GroupAttrs.groupType#</td>
                </tr>
                <tr>
                    <td nowrap="nowrap"><strong>Member Of</strong></td>
                    <td>
                        <cfset MemberOf = Group.parseGroupDNString(GroupAttrs.memberOf) />
                        <cfloop from="1" to="#ArrayLen(MemberOf)#" index="i">
                            <cfset Member = Group.SCFAD.getGroupNameByDN(MemberOf[i]) />
                            <a href="#ViewGroup##trim(Member)#">#Member#</a>
                            #( i EQ arraylen(MemberOf) ? '' : ',' )#
                        </cfloop>
                     </td>
                </tr>
                <tr>
                    <td nowrap="nowrap"><strong>Description</strong></td>
                    <td>#GroupAttrs.description#</td>
                </tr>
            </tbody>
        </table>      
    </cfform>
</cffunction>
